package com.hnucm.eatwhat_java.act;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.Toast;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.gyf.immersionbar.ImmersionBar;
import com.hnucm.eatwhat_java.R;
import com.hnucm.eatwhat_java.util.UtilApplication;
import com.hnucm.eatwhat_java.view.LuckDrawView;
import com.hnucm.eatwhat_java.view.PrizeItemView;

import java.util.Random;

public class PriceActivity extends AppCompatActivity {

    private ImageView back_btn;
    private LuckDrawView mLuckDrawView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_price);
        mLuckDrawView=findViewById(R.id.luck_draw);
        mLuckDrawView.setOnItemListener(new LuckDrawView.OnItemListener() {
            @Override
            public void onClick() {//开始抽奖
                int stayIndex = new Random().nextInt(8);
                mLuckDrawView.startGame(stayIndex);
            }

            @Override
            public void onShop(int Index) {//动画停止
                AlertDialog.Builder builder=new MaterialAlertDialogBuilder(PriceActivity.this);
                builder.setTitle("Eat What").
                        setMessage(Index>=(UtilApplication.getShopList().size())?"米饭":UtilApplication.getShopList().get(Index).getShopName()).
                        setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).create().show();
            }
        });
        if(UtilApplication.getShopList().size()>=9){
            mLuckDrawView.setData(UtilApplication.getShopList().subList(0,9));//设置奖品数据
        }else{
            mLuckDrawView.setData(UtilApplication.getShopList());//设置奖品数据
        }

        //返回
        findViewById(R.id.back_btn).setOnClickListener(v->finish());

        ImmersionBar.with(this).statusBarDarkFont(true).init();
    }
}